import { ref } from 'vue'
import { defineStore } from 'pinia'

// 用户信息
interface UserInfo {
    roleName: string
    userFullName: string
    userName: string
}
export const useUserInfo = defineStore('userInfo', () => {
    const userInfo = ref<UserInfo>()

    function setData(data: UserInfo) {
        userInfo.value = data
    }

  return { userInfo, setData }
})

// 按钮权限
interface Menu {
    _id: string
    name: string
    path: string
    type: string
    parentId: string
}
export const useUserPermission = defineStore('userPermission', () => {
    const userPermission = ref<Menu[]>([])
    const childMenu = ref<Menu[]>([])
    const activePermission = ref([])

    // 保存权限数据
    function setData(data: Menu[]) {
        userPermission.value = data
    }

    // 保存当前页面操作
    function setActivePageAction(data: any) {
        activePermission.value = data
    }

    // 设置子级菜单
    function setChildrenMenu(id: string) {
        childMenu.value = userPermission.value.filter(item => item.parentId === id)
        // console.log('childMenu.value', childMenu.value);
    }

    return { userPermission, setData, childMenu, setChildrenMenu }
})
